package com.shengyin.ec.model.dao.permission;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.shengyin.ec.model.dao.BaseDaoImpl;
import com.shengyin.ec.model.entity.Users;
import com.shengyin.ec.model.entity.Users;

@Repository(value="accountDao")
public class AccountDaoImpl extends BaseDaoImpl<Users> implements AccountDao {

	
	@Override
	public List<Users> getUsersList(int start, int end) {
		return super.findByPage("from Users", start, end);
	}

	@Override
	public void deleteSelectedUsers(Long[] ids) {
		Users goods=null;
		List<Users> goodsList=new ArrayList<Users>(0);
		for(long id:ids)
		{
			goods=super.get(id);
			goodsList.add(goods);
		}
		super.deleteAll(goodsList);
		
	}
	@Override
	public Long getTotal(){
		return (Long) super.find("select count(*) from Users").get(0);
	}

	@Override
	public List<Users> getUsersListByKeyword(String keyword, int start, int end) {
		return super.findByPage("from Users u where u.account='"+keyword+"'", start, end);
	}

	@Override
	public Users getUsersByUsername(String username) {
		ArrayList list=(ArrayList) super.find("from Users u where u.account='"+username+"'");
		int size=list.size();
		if(size==0)
			return null;
			return (Users) list.get(0);
	}

}
